from django.db import models
from gxdm.models import Dwbmdm
from .system import System


class ViewShareRecord(models.Model):
    class Meta:
        db_table = 'view_share_record'
        managed = False
        verbose_name = '视图分享记录表'
        verbose_name_plural = '视图分享记录表'
    title = models.CharField('主题', max_length=128)
    system = models.ManyToManyField(System, db_column='system', verbose_name='业务系统', blank=True, null=True)
    department = models.ForeignKey(Dwbmdm, verbose_name='申请部门', max_length=5, to_field='value', on_delete=models.PROTECT, db_column='department', blank=True, null=True)
    contact_person = models.CharField('申请人', max_length=32, blank=True, null=True, help_text='填写申请人工号')
    purpose = models.TextField('用途', blank=True, null=True)
    name = models.CharField('负责人', max_length=32)
    phone = models.CharField('联系电话', max_length=11)
    account = models.CharField('账号', max_length=32)
    host = models.CharField('访问范围', max_length=32, default='%')
    password = models.CharField('密码', max_length=64, editable=False)
    requirement = models.TextField('数据要求', blank=True, null=True)
    database = models.CharField('数据库', max_length=32, default='MySQL')
    hostname = models.CharField('主机', max_length=64, default='master.data.dgut.edu.cn')
    port = models.IntegerField('端口', default=3306)
    enable = models.BooleanField('启用')
    create_by = models.CharField('创建者', max_length=32, editable=False)
    remarks = models.CharField('备注', max_length=255, blank=True, null=True)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)
    update_time = models.DateTimeField('更新时间', auto_now=True)

    def __str__(self):
        return self.title
